package sword.offer;

/**
 * 定义一个函数，输入一个链表的头节点，反转该链表并输出反转后链表的头节点。
 *
 * @author 胡宇轩
 * @link https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/
 * @Email: yuxuan.hu01@bianlifeng.com
 */
public class TwentyFour {

    class Solution {
        public ListNode reverseList(ListNode head) {
            ListNode preNode = null;
            ListNode currNode = head;
            while(currNode != null){
                ListNode tNode = currNode.next;
                currNode.next = preNode;
                preNode = currNode;
                currNode = tNode;
            }
            return preNode;
        }
    }

    class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }
}




